package com.easyUploader.entity.factory;

import com.easyUploader.entity.dao.FileChunk;
import com.easyUploader.entity.dao.FileStorage;
import com.easyUploader.entity.dto.FileInfoDto;
import com.easyUploader.entity.vo.FileChunkVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/10/29 21:27
 */
public class FileChunkFactory {
    public static final FileChunkConverter FILE_CHUNK_CONVERTER= Mappers.getMapper(FileChunkConverter.class);

    @Mapper
    public interface FileChunkConverter {
        @Mappings ({
            @Mapping(target = "id",ignore = true),
            @Mapping(target = "createTime",ignore = true),
            @Mapping(target = "updateTime",ignore = true)
        })
        FileChunk toFileChunk(FileChunkVo fileChunkVo);

        List<FileInfoDto> toListFileInfoDto(List<FileStorage> fileStorageList);

        default FileInfoDto toFileInfoDto(FileStorage fileStorage){
            return FileInfoDto.builder().fileMd5(fileStorage.getIdentifier()).filename(fileStorage.getRealName()).path(fileStorage.getFileSavePath())
                    .build();
        }
    }
}
